package edu.pku.sei.transformation.tgg.action;

import org.eclipse.jface.action.Action;

import edu.pku.sei.transformation.editor.model.AtomicTransformation;
import edu.pku.sei.transformation.editor.views.icons.IconsProvider;
import edu.pku.sei.transformation.tgg.adapter.TGGAdapter;
import edu.pku.sei.transformation.tgg.codegen.TGGGenerator;

public class GenTGGAction extends Action {
	private AtomicTransformation transformation;
	public GenTGGAction(AtomicTransformation t) {
		this.transformation = t;
		setText("generate tgg fle");
		setImageDescriptor(IconsProvider.getImageDescriptor(IconsProvider.FILE_EXPORT_ICO));
	}
	@Override
	public void run() {
//		Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
//		.getShell();
//		FileDialog dialog = new FileDialog(shell, SWT.SAVE); 
//		dialog.setFileName(transformation.getName()+".qvt");
//		String addr = dialog.open();
//		if (addr==null)
//			return;
		TGGGenerator generator = new TGGGenerator();
		String content = generator.generate(new TGGAdapter(transformation));
		System.out.println(content);
		
//		FileWriter fw;
//		try {
//			fw = new FileWriter(addr);
//			fw.write(content, 0, content.length());
//			fw.flush();
//			fw.close();
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	}
}
